const express = require('express')
const router = express.Router()
const jwt = require('jsonwebtoken')
const key = 'itheima'
const SuccessModel = require('../module/SuccessModel')
const ErrorModel = require('../module/ErrorModel')

//登录接口
router.post('/login', (req, response) => {
    const { username, password } = req.body
    console.log('username:', username)
    console.log('password:', password)
    if (username === 'admin' && password === '123456') {
        const token = jwt.sign({ username }, key, { expiresIn: `${1000*300000}ms` })
        console.log('token:', token)
        response.send(new SuccessModel({ msg: '登录成功', token }))
    } else {
        response.send(new ErrorModel({ msg: '用户民或密码错误' }))
    }

})


module.exports = router